<!DOCTYPE html>
<html>
<head>
    <title>jQuery WeUI</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">

    <meta name="description" content="Write an awesome description for your new site here. You can edit this line in _config.yml. It will appear in your document head meta (for Google search results) and in your feed.xml site description.
    ">

    <link rel="stylesheet" href="/lib/weui.min.css">
    <link rel="stylesheet" href="/css/jquery-weui.css">
    <link rel="stylesheet" href="/css/dist.css">

</head>

<body ontouchstart>

    <header class='demos-header'>
        <h1 class="demos-title">添加商户</h1>
        <p style="color:#999;text-align: center;">请商户扫描二维码并填写商户基本信息</p>
    </header>
    <p id="img" style="width: 65%;padding-bottom: 65%;position: relative;margin: 0 auto; display:none;">
        <img data-token="<%= docs.token %>" style="position: absolute;left: 0; top: 0;width: 100%;height: 100%;" src="/images/pic_article.png" alt="" />
    </p>
    <div id="loading" class="weui-loadmore" style="width: 65%;padding-bottom: 65%;margin:0 auto;position: relative; display:block;">
        <div style="position: absolute;width: 100%;height: 100%;left:0;top:0;">
            <div style="display:table;width:100%;height:100%;">
                <div style="display: table-cell;vertical-align: middle;">
                    <p>
                        <i class="weui-loading"></i>
                        <span class="weui-loadmore__tips">正在加载</span>
                    </p>
                </div>
            </div>
        </div>
    </div>
    <div class="demos-content-padded">
        <a href="javascript:;" id="refresh" class="weui-btn weui-btn_plain-primary">刷新二维码</a>
    </div>
    <div class="weui-footer weui-footer_fixed-bottom">
        <p class="weui-footer__links">
            <a href="/http://jqweui.com" class="weui-footer__link">jQuery-WeUI 首页</a>
        </p>
        <p class="weui-footer__text">Copyright © 2016 jqweui.io</p>
    </div>
    <script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script src="/lib/jquery-2.1.4.js"></script>
    <script src="/lib/fastclick.js"></script>
    <script>
    $(function() {
        FastClick.attach(document.body);
    });
    </script>
    <script src="/js/jquery-weui.js"></script>
    <script type="text/javascript">
        var jssdk = <%- JSON.stringify(docs.jssdk) %>;
        jssdk.jsApiList = ["closeWindow","hideMenuItems"];
        wx.config(jssdk);
        wx.ready(function(){
            wx.hideMenuItems({
                menuList: [
                    "menuItem:editTag",
                    "menuItem:delete",
                    "menuItem:copyUrl",
                    "menuItem:originPage",
                    "menuItem:readMode",
                    "menuItem:openWithQQBrowser",
                    "menuItem:openWithSafari",
                    "menuItem:share:email",
                    "menuItem:share:brand",
                    "menuItem:share:appMessage",
                    "menuItem:share:timeline",
                    "menuItem:share:qq",
                    "menuItem:share:weiboApp",
                    "menuItem:favorite",
                    "menuItem:share:facebook",
                    "menuItem:share:QZone"
                ] // 要隐藏的菜单项，只能隐藏“传播类”和“保护类”按钮，所有menu项见附录3
            });
        });
        var token = $("img").data("token");
        var loading = true;
        loadings = function(){
            $.ajax({
                type: "post",
                data: {
                    token : token
                },
                dataType: "json",
                success: function(data){
                    loading = true;
                    if(!data.code && data.docs && data.docs.qrcode){
                        $("img").attr('src', data.docs.qrcode);
                        $("#img").css("display", "block");
                        $('#loading').css("display","none");
                    };
                },
                error : function(){
                    loading = true;
                }
            })
        };

        var loadingClick = function(){
            if(!loading)
                return;
            loading = false;
            $("#loading").css("display","block");
            $("#img").css("display","none");
            loadings();
        };
        $('#refresh').on("click", loadingClick);
        loadingClick();
    </script>

</body>
</html>
